package com.usian.controller;


import com.usian.pojo.User;
import com.usian.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    private final static Logger logger = LoggerFactory.getLogger(UserController.class);

    @RequestMapping("findUserAll")
    public String findUserAll(Model model){
        logger.info("info...................info");
        List<User> userList = userService.findAll();
//        for (User user : userList) {
//            System.out.println(user);
//        }
        model.addAttribute("userList",userList);
        return "index";
    }

    public void findAll(){
        List<User> userList = userService.findAll();
//        for (User user : userList) {
//            System.out.println(user);
//        }
    }

    public void findById(){
        User user=userService.findById(15);
        System.out.println(user);
    }

    public void delete() {
        userService.delete(6);
    }

    public void add() {
        User user = new User();
        user.setName("郭富城");
        user.setAge(47);
        user.setSex("男");
        user.setAddress("香港");
        user.setBirthday(new Date());
        userService.add(user);
        System.out.println(user.getId());
    }

    public void edit() {
        User user=userService.findById(7);
        user.setName("邓丽君");
        userService.edit(user);
    }
}
